
var vm = new Vue({
    el:'#wrapper',
    activated(){
        console.log("页面回来")
        getPage(this.current)
    },
    data(){
        return{
            list:[{
                "id": "",
                "courseId": "",
                "courseName": "操作系统",
                "classTime": "2022-09-07T14:11:37",
                "isDelete": "0",
                "endTime": "2022-10-07T14:11:37",
                "number": 0,
                "maxNumber": 5000,
                "credits": 2,
                "status": "1",
                "createTime": "2022-09-07T14:11:37",
                "createUser": "202200001",
                "updateTime": "2022-09-07T14:11:37",
                "updateUser": "202200001",
                "teacherName": "伍德"
            }],
            current:1,
            number:"",
            rolee:""
        }
    },
    methods:{
        deleteCourse(item){
            console.log(item)
            var $this = this;
            $.ajax({
                url:"/student/delectStudent",
                type:"delete",
                dataType:"json",
                data:{"id":item},
                async:false,
                success(data){
                    $this.$message.success("删除成功！");
                    var current = $("#current").text();
                    getPage(current);
                },
                error(){
                    $this.$message.error("删除失败！");
                }
            })
        },
        // updateStatus(item,status){
        //     var $this = this;
        //     // if(item.teacherName === "暂时未安排老师！"){
        //     //     $this.$message.error("课程未安排老师，不能启用！");
        //     //     return;
        //     // }
        //     $.ajax({
        //         url:"/student/updateStatus",
        //         dataType: "json",
        //         type:"put",
        //         data:{"courseId":item.courseId,"status":status},
        //         async: "false",
        //         success(data) {
        //             $this.$message.success("状态修改成功！");
        //             getPage($this.current)
        //         },
        //         error() {
        //             $this.$message.error("状态修改失败！");
        //         }
        //
        //     })
        // },
        jump(){
            var current = $("#page").val();
            console.log("jump:"+current);
            if(parseInt(current) < 1 || parseInt(current) >= parseInt(lastPage)+1 || parseInt(current) == NaN
                || parseInt(current) == undefined){
                vm.$message.error("你输入的数字不在范围内！");
                return
            }
            getPage(current);
        },
        toUpdate(id){
            window.location.href= "user-message.html?updateStudentId="+id;
        },
        toAdd(){
            window.location.href= "user-message.html?addStudent=true";
        },
        exportData(){
            $.ajax({
                url:"/studentCourse/exportData",
                type:"get",
                dataType:"json",
                async:false,
                success(data){
                    vm.$message.success("打印成功，文件存放在D盘目录下");
                    console.log("打印成功")
                },
                error(){
                    vm.$message.error("打印失败");
                    console.log("打印失败")
                }

            })
        },
        importData() {
            $("#fileForm").submit();
        }

    }
});

$(function (){



    getPage(vm.current);
    var lastPage = $("#lastPage").text();
    $("#homePage").click(function (){
        getPage(1);
    })
    $("#backPage").click(function (){
        getPage(lastPage);
    })
    $("#next").click(function (){

        lastPage = $("#lastPage").text();
        vm.current++;
        if(vm.current > parseInt(lastPage)){
            vm.current = lastPage;
            return;
        }
        getPage(vm.current);
    })
    $("#prev").click(function (){
        lastPage = $("#lastPage").text();
        vm.current--;
        if(vm.current < 1){
            vm.current = 1;
            return
        }
        getPage(vm.current);
    })
    $("#courseSearch").click(function (){
        console.log("搜索功能开始：");
        getPage(1);
    })


    // $("#start").click(function (){
    //     //     var start = $(this);
    //     //
    //     //     var flag = $(this).prev().text() === "暂时未安排老师！";
    //     //     var status = start.val();
    //     //     var courseId = start.parent().parent().children(".cId").text();
    //     //     if(flag){
    //     //         alert("请先为课程安排老师！");
    //     //         return
    //     //     }
    //     //
    //     // })
    //setInterval("getPage(vm.current)",1000)
})

function getPage(current){
    var courseId = $("#studentId").val();
    var courseName = $("#studentName").val();
    console.log(courseId+","+courseName)
    $.ajax({
        url: "/student/findStudent",
        type: "get",
        dataType:"json",
        data:{"page":parseInt(current),"limit":8,"studentName":courseName,"studentId":courseId},
        async:true,
        success(data){

            console.log(data);
            vm.list = data.data.iPage.records;
            $("#current").html(" &nbsp;"+data.data.iPage.current+"&nbsp; ");
            $("#lastPage").html(data.data.iPage.pages);

        },
        error(){
            vm.$message.error("数据获取失败！");
        }
    })

}

